﻿namespace EFS.RC.Wallboard.Common.Config.Sections.Phones
{
	public class All
	{
		#region Locals
		// all dictionary
		private System.Collections.Generic.Dictionary<System.String, EFS.RC.Wallboard.Common.Config.Sections.Phones.Phone> allDictionary =
			new System.Collections.Generic.Dictionary<System.String, EFS.RC.Wallboard.Common.Config.Sections.Phones.Phone>();
		#endregion

		#region Cosnstructors
		/// Static
		static All()
		{
			Instance = new All();
		}

		/// Implicit
		private All()
		{
			LoadConfig();
		}
		#endregion

		#region Properties
		/// Property All: Get, Set
		public static All Instance { get; private set; }

		/// Property All: Get, Set
		public EFS.RC.Wallboard.Common.Config.Sections.Phones.Phone this[System.String uri]
		{
			get
			{
				if (allDictionary.ContainsKey(uri))
				{
					return allDictionary[uri];
				}
				return null;
			}
			private set
			{
				allDictionary[uri] = value;
			}
		}
		#endregion

		/// LoadConfig
		private void LoadConfig()
		{
			// get configuration
			System.Configuration.Configuration config = 
				System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal);
			EFS.Common.Verify.Reference(config, "config");

			// get sectionGroupPhones
			System.Configuration.ConfigurationSectionGroup sectionGroupPhones = config.GetSectionGroup("Phones");
			EFS.Common.Verify.Reference(sectionGroupPhones, "sectionGroupPhones");

			// cicle all
			foreach (System.Configuration.ConfigurationSectionGroup sectionGroupPhone in sectionGroupPhones.SectionGroups)
			{
				// create phone
				EFS.RC.Wallboard.Common.Config.Sections.Phones.Phone phone = new EFS.RC.Wallboard.Common.Config.Sections.Phones.Phone(sectionGroupPhone);
				this[phone.Uri] = phone;
			}
		}
	}

}